home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 611 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: news.clark.net!not-for-mail
  2. From: dickey@clark.net (T.E.Dickey)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Restrictions on qsort compare function?
  5. Date: 20 Mar 1996 13:47:52 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Distribution: world
  8. Message-ID: <4ip2a8$p8b@clarknet.clark.net>
  9. References: <4iokop$h4p@lyra.csx.cam.ac.uk>
  10. NNTP-Posting-Host: explorer.clark.net
  11. Mime-Version: 1.0
  12. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  13. Content-Transfer-Encoding: 8bit
  14. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  15.  
  16. James Bonfield (jkb@mrc-lmb.cam.ac.uk) wrote:
  17. : Are there any limitations on what the sort function passed over to qsort can
  18. : do or return? I know it's meant to return < 0, 0 or > 0 for the various
  19. : compare operations, but which you return is purely up to your own comparison
  20. : system.
  21. In general, qsort will malfunction (at the least, you can get incorrect
  22. sorting!) if
  23.  
  24.     compare(a,b) > 0 && compare(b,a) >= 0
  25. or
  26.     compare(b,a) > 0 && compare(a,b) >= 0
  27.  
  28. because it's not able to put the elements into disjoint sets.
  29.  
  30. -- 
  31. Thomas E. Dickey
  32. dickey@clark.net
  33.